using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

using LDAP.Entity;

namespace LDAP.BLL
{
    public class BizAccessrecord
    {
		public const string ENTITY_KEY = "accessrecord";
		
        public static long Add(Accessrecord entry)
        {
            SqlServerCommon.GetMapper(ENTITY_KEY, entry).Insert("Insert_Accessrecord", entry).ToString();
            return (long)entry.Id;
        }

        public static int Update(Accessrecord entry)
        {
            return SqlServerCommon.GetMapper(ENTITY_KEY, entry).Update("Update_Accessrecord", entry);
        }

        public static Accessrecord GetByKey(int id)
        {
            return SqlServerCommon.GetMapper(ENTITY_KEY, id).QueryForObject<Accessrecord>("Select_Accessrecord", id);
        }

        public static IList<Hashtable> GetUserAccessRecord(string userId, DateTime min, DateTime max) {
            Hashtable ht = new Hashtable();
            ht["userId"]= userId;
            ht["min"]= min.ToString("yyyy-MM-dd");
            ht["max"]= max.ToString("yyyy-MM-dd");
            return SqlServerCommon.GetMapper(ENTITY_KEY, ht).QueryForList<Hashtable>("select_user_record", ht);
        }

        public static IList<Hashtable> GetUserListAccessRecord(string userList, DateTime min, DateTime max) { 
            Hashtable ht = new Hashtable();
            ht["userList"] = userList;
            ht["min"]= min.ToString("yyyy-MM-dd");
            ht["max"]= max.ToString("yyyy-MM-dd");
            return SqlServerCommon.GetMapper(ENTITY_KEY, ht).QueryForList<Hashtable>("select_userlist_record", ht);
        }

        public static int Delete(int id)
        {
            return SqlServerCommon.GetMapper(ENTITY_KEY, id).Delete("Delete_Accessrecord", id);
        }
    }
}

	